/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entities;

import Connection.Koneksi;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;

/**
 *
 * @author JackOddie
 */
public class Karyawan {

    private String username;
    private String password;
    private String statusAkses; //admin or staff

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getStatusAkses() {
        return statusAkses;
    }

    public void setStatusAkses(String statusAkses) {
        this.statusAkses = statusAkses;
    }

    public void login(String username, String password) throws SQLException {
        try {
            String query = "select * from KARYAWAN where USER_NAME='" + username
                    + "' AND PASSWORD='" + password + "'";
            ResultSet rs = Koneksi.select(query);
            if (rs != null) {
                while (rs.next()) {
                    setUsername(rs.getString(1));
                    setPassword(rs.getString(2));
                    setStatusAkses(rs.getString(3));
                }
            } else {
                setUsername(null);
                setPassword(null);
                setStatusAkses(null);
            }
        }catch(NullPointerException ex){
            JOptionPane.showMessageDialog(null, "gagal login");
        }


    }
}
